unit cnctcfg;

interface

uses
  Windows, DB, ADODB, Dialogs, Controls, RzButton, StdCtrls, Classes, Forms, IniFiles,
  SysUtils;

type
  Tdbcntfrm = class(TForm)
    Label1: TLabel;
    Label2: TLabel;
    Edit1: TEdit;
    Edit2: TEdit;
    RzButton1: TRzButton;
    RzButton3: TRzButton;
    RzButton4: TRzButton;
    RzButton5: TRzButton;
    OpenDialog1: TOpenDialog;
    ADOConnection1: TADOConnection;
    procedure RzButton5Click(Sender: TObject);
    procedure RzButton1Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure RzButton4Click(Sender: TObject);
  private
    { Private declarations }
    function TestAdo(DataSource:string;Password:string):Boolean;
  public
    { Public declarations }
  end;

var
  dbcntfrm: Tdbcntfrm;

implementation

{$R *.dfm}

uses includefile;

procedure Tdbcntfrm.RzButton5Click(Sender: TObject);
begin
  Close;
end;

procedure Tdbcntfrm.RzButton1Click(Sender: TObject);
//var
//  Rct:TRect;
begin
  //GetClipCursor(Rct);
  //OpenDialog1.Filter:=
  //  'Microsoft Access Application(*.mdb)|*.mdb|Microsoft Access MDE Database(*.mde)|*.mde';
  //ClipCursor(NIL);
  OpenDialog1.Execute;
  Edit1.Text:=OpenDialog1.FileName;
  //ClipCursor(@Rct);
end;

procedure Tdbcntfrm.FormCreate(Sender: TObject);
begin
  //inif:=TiniFile.Create(GetAppPath+'\berry.dll');
  Edit1.Text:=inif.ReadString('system','dbsource','cmcrj.mdb');
  //tmpfp.Free;
end;

function Tdbcntfrm.TestAdo(DataSource:string;Password:string):Boolean;
var
  tmpStr:string;
begin
  tmpStr:=Format(DBCNCTSTR,[DataSource,Password]);
  ADOConnection1.ConnectionString:=tmpStr; 
  try
    ADOConnection1.Open;
    Result:=True;
    ADOConnection1.Close;
  except
    Result:=False;
  end;
end;

procedure Tdbcntfrm.RzButton4Click(Sender: TObject);
begin
  if TestAdo(Trim(Edit1.Text),Trim(Edit2.Text)) then begin
    //tmpfp:=TiniFile.Create(GetAppPath+'\berry.dll');
    inif.WriteString('system','dbsource',Trim(Edit1.Text));
    inif.WriteString('system','dbpassword',Trim(Edit2.Text));
    //tmpfp.Free;
    Application.MessageBox('SETUP IS SUCCESSFULL,NOW RESTART.','INFORMATION',MB_ICONINFORMATION);
    WinExec(pchar(paramstr(0)),SW_SHOW);
    Application.Terminate;
  end else begin
    Application.MessageBox(pchar('Connect test is not success '),pchar('Error'),16);
    Edit2.Text:='';
    Edit2.SetFocus;
  end;
end;

end.
